home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Airstrike.lua next >
Text File  |  2010-08-31  |  4KB  |  120 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Airstrike + Projectile Cluster
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.airstrike={}
  10. cc.airstrike.cluster={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.airstrike.gfx_wpn=loadgfx("weapons/rc.bmp")                            -- Weapon Image
  14. setmidhandle(cc.airstrike.gfx_wpn)
  15. cc.airstrike.gfx_icon=loadgfx("weapons/airstrikeicon.png")                -- Weapon Icon
  16. setmidhandle(cc.airstrike.gfx_icon)
  17. cc.airstrike.gfx_pro=loadgfx("weapons/cluster.bmp")                        -- Projectile Image
  18. setmidhandle(cc.airstrike.gfx_pro)
  19. cc.airstrike.sfx_attack=loadsfx("airstrike.ogg")                        -- Attack Sound
  20.  
  21. --------------------------------------------------------------------------------
  22. -- Weapon: Airstrike
  23. --------------------------------------------------------------------------------
  24.  
  25. cc.airstrike.id=addweapon("cc.airstrike","Air Strike",cc.airstrike.gfx_icon,1,2)    -- Add Weapon (1 use, first in round 2)
  26.  
  27. function cc.airstrike.draw()                                                    -- Draw
  28.     setblend(blend_alpha)
  29.     setalpha(1)
  30.     setcolor(255,255,255)
  31.     drawinhand(cc.airstrike.gfx_wpn,7,0)
  32.     -- HUD Positioning
  33.     if weapon_shots==0 then
  34.         hudpositioning(pos_invisible)
  35.     end
  36. end
  37.  
  38. function cc.airstrike.attack(attack)                                    -- Attack
  39.     if (weapon_shots<=0) and (weapon_position==1) then
  40.         -- No more weapon switching!
  41.         useweapon(0)
  42.         playsound(cc.airstrike.sfx_attack)
  43.         weapon_shots=weapon_shots+1
  44.         -- Attack
  45.         for i=-2,2,1 do
  46.             pid=createprojectile(cc.airstrike.cluster.id)
  47.             projectiles[pid]={}
  48.             projectiles[pid].x=weapon_x+(i*15)
  49.             projectiles[pid].y=-500
  50.             projectiles[pid].sx=0
  51.             projectiles[pid].sy=3.0
  52.             if i==0 then projectiles[pid].follow=1 end
  53.         end
  54.         -- End Turn
  55.         endturn()
  56.     end
  57. end
  58.  
  59. --------------------------------------------------------------------------------
  60. -- Projectile: Cluster
  61. --------------------------------------------------------------------------------
  62.  
  63. cc.airstrike.cluster.id=addprojectile("cc.airstrike.cluster")    -- Add Projectile
  64.  
  65. function cc.airstrike.cluster.draw(id)                            -- Draw
  66.     -- Setup draw mode
  67.     setblend(blend_alpha)
  68.     setalpha(1)
  69.     setcolor(255,255,255)
  70.     setscale(1,1)
  71.     -- Calculate projectile rotation
  72.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  73.     -- Draw projectile
  74.     drawimage(cc.airstrike.gfx_pro,projectiles[id].x,projectiles[id].y)
  75. end
  76.  
  77. function cc.airstrike.cluster.update(id)                            -- Update
  78.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  79.     -- Particle Tail
  80.     particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  81.     particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  82.     particlefadealpha(0.05)
  83.     -- Wind + Gravity influence on speed
  84.     projectiles[id].sx=projectiles[id].sx+getwind()*0.3
  85.     projectiles[id].sy=projectiles[id].sy+getgravity()
  86.     -- Move (in substep loop for optimal collision precision)
  87.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  88.     msubx=projectiles[id].sx/msubt
  89.     msuby=projectiles[id].sy/msubt
  90.     for i=1,msubt,1 do
  91.         projectiles[id].x=projectiles[id].x+msubx
  92.         projectiles[id].y=projectiles[id].y+msuby
  93.         -- Collision
  94.         if collision(col3x3,projectiles[id].x,projectiles[id].y)==1 then
  95.             -- Cause damage
  96.             arealdamage(projectiles[id].x,projectiles[id].y,70,25)
  97.             -- Destroy terrain
  98.             terrainexplosion(projectiles[id].x,projectiles[id].y,15,1)
  99.             -- Crater
  100.             grey=math.random(0,40)
  101.             terrainalphaimage(gfx_crater75,projectiles[id].x,projectiles[id].y,math.random(5,7)*0.1,grey,grey,grey)
  102.             -- Free projectile
  103.             freeprojectile(id)
  104.             break
  105.         end
  106.         -- Water
  107.         if (projectiles[id].y)>getwatery()+5 then
  108.             -- Effects
  109.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  110.             playsound(sfx_hitwater1)
  111.             -- Free projectile
  112.             freeprojectile(id)
  113.             break
  114.         end
  115.     end
  116.     -- Scroll to projectile
  117.     if projectiles[id].follow==1 then
  118.         scroll(projectiles[id].x,projectiles[id].y)
  119.     end
  120. end